using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Oracle.DataAccess.Client;using Oracle.DataAccess.Types;

public partial class Home : System.Web.UI.Page
{

    protected univBanco Banco;
    protected univNETLib currentNetlib;

    protected void Page_Load(object sender, EventArgs e)
    {
        Banco = (univBanco)Session[modzGeneral.mUsu_codigo + "Banco"];
        currentNetlib = (univNETLib)Session[modzGeneral.mUsu_codigo + "NetLib"];

        string strIdioma = currentNetlib.StrIdioma;

        string sql = "";
        if (currentNetlib.gUserType == "A")
        {
            sql = "select nome" + strIdioma +
                         ", descricao" + strIdioma +
                         ", picture, syn_funcao " +
                         "from syn_funcao_web " +
                         "where fun_tipo = 'M' " +
                         " and syn_funcao = 'SS_COMUNS' " +
                         "order by level_code";
        }
        else
        {
            if (currentNetlib.gUserType == "U")
            {
                sql = "SELECT nome" + strIdioma +
                    ", descricao" + strIdioma +
                    ", picture, t.syn_funcao " +
                    " FROM syn_permissao_total_usu a, syn_funcao_web t " +
                    " where t.syn_funcao = a.syn_funcao " +
                    " and t.fun_tipo = 'M' " +
                    " and a.usu_codigo = '" + ((univNETLib)Session[modzGeneral.mUsu_codigo + "NetLib"]).usu_codigo + "' " +
                    " and a.selecionar = 'S' " +
                    " ORDER BY T.level_code ";
            }
            else
            {
                sql = "select nome" + strIdioma +
                             ", descricao" + strIdioma +
                             ", picture, syn_funcao " +
                             "from syn_funcao_web " +
                             "where fun_tipo = 'M' " +
                             "order by level_code";
            }
        }
        
        OracleDataReader reader;
        Banco.OpenRecordSet(sql, out reader);
        while (reader.Read())
        {
            addAtalho(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString());
        }
        lblUsuario.Text = ((univNETLib)Session[modzGeneral.mUsu_codigo + "NETLib"]).usu_codigo + " / " + Session[modzGeneral.mUsu_codigo + "LOG_DATABASE"].ToString(); //((univBanco)Session[modzGeneral.mUsu_codigo + "Banco"]).SelectInto("select sys_context('USERENV', 'AUTHENTICATED_IDENTITY') from dual") + "@" + DBConnection.GetConnection().DataSource;

    }

    protected void addAtalho(String titulo, String descricao, String imagem, String url)
    {
        Panel aPanel = new Panel();        
        aPanel.CssClass = "Atalho";
        aPanel.Attributes.Add("onmouseover", "Over2(this);");
        aPanel.Attributes.Add("onmouseout", "Out2(this);");
        aPanel.Attributes.Add("onclick", "FreezePage();location.href='Util/Modulos/Mod_Geral.aspx?modulo=" + url + "';");
        aPanel.Visible = currentNetlib.getModVisible(url);

        Label aTitulo = new Label();
        aTitulo.CssClass = "Titulo";
        aTitulo.Text = titulo;

        Label aDescricao = new Label();
        aDescricao.CssClass = "Texto";
        aDescricao.Text = descricao;

        Panel aImgPanel = new Panel();
        aImgPanel.CssClass = "Imagem";
        Image aImg = new Image();
        aImg.ImageUrl = getUrlByNumber(12); //getUrlByNumber(Int32.Parse(imagem));
        aImgPanel.Controls.Add(aImg);

        aPanel.Controls.Add(aImgPanel);
        aPanel.Controls.Add(aTitulo);
        aPanel.Controls.Add(aDescricao);

        pAtalhos.Controls.Add(aPanel);
    }

    protected string getUrlByNumber(int i)
    {
        string img = "";
        switch (i)
        {
            case 1: { img = "adi.bmp"; break; }
            case 2: { img = "admin.bmp"; break; }
            case 3: { img = "bank.bmp"; break; }
            case 4: { img = "cash.bmp"; break; }
            case 5: { img = "collection.bmp"; break; }
            case 6: { img = "fx.bmp"; break; }
            case 7: { img = "gl.bmp"; break; }
            case 8: { img = "marketdata.bmp"; break; }
            case 9: { img = "payment.bmp"; break; }
            case 10: { img = "reconciliation.bmp"; break; }
            case 11: { img = "reporting.bmp"; break; }
            case 12: { img = "setup.bmp"; break; }
            default: { img = "DefaultModulo.bmp"; break; }
        }

        return "~/App_Themes/Style/images/modulos/" + img;
    }

    public void translateTermo(string termo)
    {
        #region Fixo Idioma Browser
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(currentNetlib.Idioma);
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(currentNetlib.Idioma);
        #endregion

        Response.Write(Resources.Home.ResourceManager.GetString(termo));
    }

    protected void lblLogof_Click(object sender, EventArgs e)
    {
        string mpageend = "~/Login.aspx?ReturnUrl=Main.aspx";
        DBConnection.CloseConnection();
        Session.Abandon();
        Response.Redirect(mpageend);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

    }
}